package com.ruoyi.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.domain.Orderdetail;
import com.ruoyi.shop.service.IOrderdetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * orderdetailController
 *
 * @author ruoyi
 * @date 2025-06-08
 */
@Anonymous
@RestController
@RequestMapping("/shop/orderdetail")
public class OrderdetailController extends BaseController
{
    @Autowired
    private IOrderdetailService orderdetailService;

    /**
     * 查询orderdetail列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Orderdetail orderdetail)
    {
        startPage();
        List<Orderdetail> list = orderdetailService.selectOrderdetailList(orderdetail);
        return getDataTable(list);
    }

    /**
     * 导出orderdetail列表
     */
    @Log(title = "orderdetail", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Orderdetail orderdetail)
    {
        List<Orderdetail> list = orderdetailService.selectOrderdetailList(orderdetail);
        ExcelUtil<Orderdetail> util = new ExcelUtil<Orderdetail>(Orderdetail.class);
        util.exportExcel(response, list, "orderdetail数据");
    }

    /**
     * 获取orderdetail详细信息
     */
    @GetMapping(value = "/{detailid}")
    public AjaxResult getInfo(@PathVariable("detailid") Long detailid)
    {
        return AjaxResult.success(orderdetailService.selectOrderdetailByDetailid(detailid));
    }

    /**
     * 新增orderdetail
     */
    @Log(title = "orderdetail", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Orderdetail orderdetail)
    {
        return toAjax(orderdetailService.insertOrderdetail(orderdetail));
    }

    /**
     * 修改orderdetail
     */
    @Log(title = "orderdetail", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Orderdetail orderdetail)
    {
        return toAjax(orderdetailService.updateOrderdetail(orderdetail));
    }

    /**
     * 删除orderdetail
     */
    @Log(title = "orderdetail", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailids}")
    public AjaxResult remove(@PathVariable Long[] detailids)
    {
        return toAjax(orderdetailService.deleteOrderdetailByDetailids(detailids));
    }
}
